package com.origin.file.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.origin.common.result.RestPageResult;
import com.origin.common.result.RestResult;
import com.origin.file.service.INoticeService;
import com.origin.file.entity.domain.Notice;
import com.origin.file.entity.dto.notice.NoticeListDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "公告管理")
@RestController
@RequestMapping("/notice")
public class NoticeController {
    public static final String CURRENT_MODULE = "公告管理";
    @Resource
    INoticeService noticeService;

    /**
     * 得到所有的公告
     *
     * @return
     */
    @Operation(summary = "得到所有的公告列表", tags = {"公告管理"})
    @GetMapping("/list")
    public RestPageResult<List<Notice>> selectUserList(
            @Parameter(description = "当前页，从1开始") @RequestParam(defaultValue = "1") int page
            , @Parameter(description = "页大小") @RequestParam(defaultValue = "10") int pageSize
            , @Parameter(description = "标题") @RequestParam(required = false) String title
            , @Parameter(description = "发布者") @RequestParam(required = false) Long publisher
            , @Parameter(description = "开始发布时间") @RequestParam(required = false) String beginTime
            , @Parameter(description = "开始发布时间") @RequestParam(required = false) String endTime) {
        NoticeListDTO noticeListDTO = new NoticeListDTO();
        noticeListDTO.setPage(page);
        noticeListDTO.setPageSize(pageSize);
        noticeListDTO.setTitle(title);
        noticeListDTO.setPlatform(3);
        noticeListDTO.setPublisher(publisher);
        noticeListDTO.setBeginTime(beginTime);
        noticeListDTO.setEndTime(endTime);
        IPage<Notice> noticeIPage = noticeService.selectUserPage(noticeListDTO);
        return RestPageResult.success(noticeIPage.getRecords(), noticeIPage.getTotal(), noticeIPage.getSize(), noticeIPage.getCurrent());
    }

    @Operation(summary = "查询公告详情", tags = {"公告管理"})
    @GetMapping("/detail")
    public RestResult<Notice> getNoticeDetail(@Parameter(description = "公告id", required = true) long noticeId) {
        Notice notice = noticeService.getById(noticeId);
        return RestResult.success(notice);
    }


}
